<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<div id="main">

		</div>
		<button type="button" onclick="a2()">创建连接</button>
		<button type="button" onclick="a3()">删除节点</button>
		<script type="text/javascript">
			// function a1() {
			// 	var img = document.createElement("img");
			// 	img.setAttribute("src", "img/1.jpeg");
			// 	var main = document.getElementById("main");
			// 	main.appendChild(img);
			// }


			function a2() {
				var a = document.createElement("a");
				a.setAttribute("href", "https://www.baidu.com");
				a.innerHTML = "百度一下";
				var main = document.getElementById("main");
				main.appendChild(a);
			}

			function a3() {
				var main = document.getElementById("main");
				var childs = main.childNodes;
				// for (var i = childs.length - 1; i >= 0; i--) {
				// 	main.removeChild(childs[i]);
				// }
				var len = childs.length;
				for(i = 0 ;i < len ; i++){
					main.removeChild(childs[0]);
				}
			}

		</script>
	</body>
</html>
